﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPDemo
{
    public partial class OrdersSummary : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string name = Session["username"].ToString();
                GetOrders(name);
            }
        }

        protected void GetOrders(string name)
        {
            DataTable dt = Payment.listOrders(name);

            Orders_Summary_GV.DataSource = dt;
            Orders_Summary_GV.DataBind();
        }

        protected void getOrderDetails(string orderID)
        {
            DataTable dt = Payment.listOrderDetails(orderID);
            lblOrderID.Text = dt.Rows[0][0].ToString();
            lblTotalPrice2.Text = dt.Rows[0][6].ToString();
            Order_Details_GV.DataSource = dt;
            Order_Details_GV.DataBind();
        }

        protected void Orders_Summ_Grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            string name = Session["username"].ToString();
            this.Orders_Summary_GV.PageIndex = e.NewPageIndex;
            GetOrders(name);
        }

        protected void Order_Details_Grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            string orderID = Session["orderID"].ToString();
            this.Orders_Summary_GV.PageIndex = e.NewPageIndex;
            getOrderDetails(orderID);
        }

        protected void Orders_Summ_Grid_SelectedIndexChanged(object sender, EventArgs e)
        {
            string orderID = Orders_Summary_GV.SelectedDataKey.Value.ToString();

            Session["orderID"] = orderID;

            getOrderDetails(orderID);
            order_details.Style.Add("display", "block");
            btnPay.Enabled = true;
        }

        protected void btnPay_Click(object sender, EventArgs e)
        {
            Response.Redirect("MakePayment.aspx");
        }
    }
}